{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "18fe0ed9",
   "metadata": {},
   "source": [
    "# python课堂笔记 week08"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aec79020",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "1.代码注释\n",
    "2.用户输入\n",
    "3.格式化输入"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4624eb1",
   "metadata": {},
   "source": [
    "# 1代码的注释\n",
    "\n",
    ">1.#,一般写在代码块最上边，或者每一行代码最后，用于代码思路的记录\n",
    ">2.\"注释内容“一般是注释代码块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "05cde3fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "#author：chouerti"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e7dfd591",
   "metadata": {},
   "outputs": [],
   "source": [
    "#三个引号注释代码块内容，不运行"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23854d35",
   "metadata": {},
   "source": [
    "# 2用户输入\n",
    ">1.input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b2a7b0d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:chouerti\n",
      "密码:123456\n",
      "chouerti\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "fc6e624e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:chouerti\n",
      "密码:1234\n",
      "账号不存在或密码不正确!\n"
     ]
    }
   ],
   "source": [
    "#登陆系统 完善 迭代1：增加判断功能\n",
    "#假设我们数据库有用户信息：账号：chouerti，密码:123456\n",
    "user1=\"chouerti\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "#情景一：输入信息正确 登陆成功\n",
    "if user1 == username and password1 == password:\n",
    "    print(\"欢迎\"+user1+\"登录!\")\n",
    "#情景2 账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f00b3c5a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:chouerti\n",
      "密码:1234\n",
      "账号不存在或密码不正确!\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"type\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m<cell line: 6>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     17\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m三次输入失败 请一小时后再来尝试\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m     18\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m账号不存在或密码不正确!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 19\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m您还有\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[38;5;241m+\u001b[39m(i\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m次尝试的机会\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"type\") to str"
     ]
    }
   ],
   "source": [
    "#登陆系统 迭代2 增加循环功能\n",
    "#假设我们数据库有用户信息：账号：chouerti，密码:123456\n",
    "user1 = \"chouerti\"\n",
    "password1 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1): # i 是一个 int\n",
    "    username = input(\"账号:\")\n",
    "    password = input(\"密码:\")\n",
    "\n",
    "    #情景一：输入信息正确 登陆成功\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登录!\")\n",
    "        break #终止循环\n",
    "    #情景2 账号不存在或密码不正确\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败 请一小时后再来尝试\")\n",
    "        print(\"账号不存在或密码不正确!\")\n",
    "        print(\"您还有\"+str+(i-1)+ \"次尝试的机会\")#str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41f1c7e4",
   "metadata": {},
   "source": [
    "# 格式化输出\n",
    ">1.用户注册系统"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0dd19520",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOF while scanning triple-quoted string literal (3389311257.py, line 14)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [11]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(info)\u001b[0m\n\u001b[1;37m               \n^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOF while scanning triple-quoted string literal\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统 #方法一 字符传拼接发\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info = '''-----INFO OF'''+name+'''------'''+'''\n",
    "年龄：'''+age+'''\n",
    "工作：'''+job+'''\n",
    "收入：'''+salary+'''\n",
    "地区：'''+reg+'''\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "d768ae39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：chouerti\n",
      "年龄：19\n",
      "工作：yb\n",
      "收入：100000000\n",
      "地区：河南\n",
      "-----INFO OF chouerti-----\n",
      "年龄：19\n",
      "工作：yb\n",
      "收入：100000000\n",
      "地区：河南\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统 #方法二 占位符%s 依次有序输入\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info = '''-----INFO OF %s-----\n",
    "年龄：%s\n",
    "工作：%s\n",
    "收入：%s\n",
    "地区：%s'''%(name,age,job,salary,reg)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ba2f9593",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '，' (U+FF0C) (1145960005.py, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [14]\u001b[1;36m\u001b[0m\n\u001b[1;33m    地区：{地区}'''.format(年龄 = age，姓名 = name，工作 = job，收入 = salary，地区 = reg)\u001b[0m\n\u001b[1;37m                              ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character '，' (U+FF0C)\n"
     ]
    }
   ],
   "source": [
    "#用户注册系统 方法三 format()格式化输出函数\n",
    "name = input(\"姓名：\")\n",
    "age = int(input(\"年龄：\"))#强制将str转化为int\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "reg = input(\"地区：\")\n",
    "\n",
    "info='''-----INFO OF (姓名)-----\n",
    "姓名：{姓名}\n",
    "年龄：{年龄}\n",
    "工作：{工作}\n",
    "收入：{收入}\n",
    "地区：{地区}'''.format(年龄 = age，姓名 = name，工作 = job，收入 = salary，地区 = reg)\n",
    "print(info)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2b872d9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c26fdcb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
